Fixed two segfaults involving stack filter: empty lists didn't push right, and we...
authorparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 8 Dec 2004 14:53:21 +0000 (14:53 +0000)
committerparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 8 Dec 2004 14:53:21 +0000 (14:53 +0000)
gpsbabel/defs.h
gpsbabel/queue.h
gpsbabel/stackfilter.c
gpsbabel/waypt.c

index 5f008e1ec48bbfc5029586aad45ccbc88912ffcd..e0ac7e40c3f85517b586080cbe2e6372bd57e6d9 100644 (file)
@@ -266,6 +266,7 @@ void waypt_compute_bounds(bounds *);
 void waypt_flush(queue *);
 void waypt_flush_all(void);
 unsigned int waypt_count(void);
+void set_waypt_count(unsigned int nc);
 void free_gpx_extras (xml_tag * tag);
 void xcsv_setup_internal_style(const char *style_buf);
 void xcsv_read_internal_style(const char *style_buf);
index 2cbb72748eb574a3eb125392b10659b4c3759332..e042e235e2de6580847652d86845e35a3a58ce5f 100644 (file)
@@ -33,10 +33,15 @@ queue * dequeue(queue *element);
 #define QUEUE_LAST(head) (head)->prev
 #define QUEUE_EMPTY (head)->next == head
 #define QUEUE_MOVE(newhead,oldhead) \
-       (newhead)->next = (oldhead)->next; \
-       (newhead)->prev = (oldhead)->prev; \
-       (newhead)->next->prev = (newhead); \
-       (newhead)->prev->next = (newhead); \
+        if ( (oldhead)->next == (oldhead) ) {\
+               (newhead)->next = (newhead)->prev = (newhead); \
+       } \
+       else { \
+               (newhead)->next = (oldhead)->next; \
+               (newhead)->prev = (oldhead)->prev; \
+               (newhead)->next->prev = (newhead); \
+               (newhead)->prev->next = (newhead); \
+       } \
        (oldhead)->next = (oldhead)->prev = (oldhead)
 
 #define ENQUEUE_TAIL(listhead, element) \
index adb3a91444ef6ab1cac55f4b603bb697caad8367..c8c5021fb13bba98196c34326af43146ee8b909b 100644 (file)
@@ -62,6 +62,7 @@ arglist_t stackfilt_args[] = {
 
 struct stack_elt {
        queue waypts;
+       unsigned int waypt_ct;
        struct stack_elt *next;
 } *stack = NULL;
 
@@ -74,10 +75,13 @@ stackfilt_process(void)
        queue *tmp = NULL;
        queue tmp_queue;
        waypoint *wpt_tmp;
+       unsigned int tmp_count;
        
        if ( opt_push ) {
                tmp_elt = (struct stack_elt *)xmalloc(sizeof(struct stack_elt));
                QUEUE_MOVE(&(tmp_elt->waypts), &waypt_head);
+               tmp_elt->waypt_ct = waypt_count();
+               set_waypt_count(0);
                tmp_elt->next = stack;
                stack = tmp_elt;
                if ( opt_copy ) {
@@ -102,6 +106,7 @@ stackfilt_process(void)
                else {
                        waypt_flush( &waypt_head );
                        QUEUE_MOVE(&(waypt_head), &(stack->waypts) );
+                       set_waypt_count(stack->waypt_ct);
                }
                stack = tmp_elt->next;
                xfree( tmp_elt );
@@ -118,6 +123,10 @@ stackfilt_process(void)
                QUEUE_MOVE(&tmp_queue, &(tmp_elt->waypts) );
                QUEUE_MOVE(&(tmp_elt->waypts), &waypt_head );
                QUEUE_MOVE(&waypt_head, &tmp_queue );
+               
+               tmp_count = waypt_count();
+               set_waypt_count( tmp_elt->waypt_ct );
+               tmp_elt->waypt_ct = tmp_count;
        }
 }
 
index fde54f87b344e3100183434402205c79278cdc5c..ae15046f44cf728acf5e29d442bed112f2d86c1d 100644 (file)
@@ -135,6 +135,12 @@ waypt_count(void)
        return waypt_ct;
 }
 
+void
+set_waypt_count(unsigned int nc)
+{
+       waypt_ct = nc;
+}
+
 void
 waypt_disp(const waypoint *wpt)
 {